package com.itheima.test1;

public class MyFactoryDemo2 {
    public static void main(String[] args) {
        //案例:求1-100之间的和
        int sum= getSum(100);
        System.out.println(sum );

    }

    private static int getSum(int i) {
        //方法作用:求1-i之间的和
            //100+(1-99之间的和)
                //99+(1-98之间的和)
                    //...
                        //1
        if(i == 1){
            return 1;
        }else{
            return i + getSum(i -1);
        }
    }
}
